package com.yyfax.ph.personal.authority.bankcard.model;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * M: 获取所属银行
 * Created by ying_he on 2017/6/12.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class GetOwnedBankModel extends Model {
	private static final String TAG = GetOwnedBankModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getOwnedBank(token, (RequestParams) params);
	}

	@Override
	public void onNext(Object entity) {
		CLog.i(TAG, "onNext: " + entity.toString());
		OwnedBankResult result = cast(entity);
		EventAgent.post(result);
	}

	private interface Service {
		@POST("account/card/bin")
		Observable<OwnedBankResult> getOwnedBank(@Header("token") String token, @Body RequestParams params);
	}

	public static class OwnedBankResult extends BaseResultEntity<OwnedBank> {
	}

	public static class OwnedBank {
		/**
		 * 银行代码（非支持银行返回""）
		 */
		public String bankCode;
		/**
		 * 银行简称
		 */
		public String bankId;
		/**
		 * 开户行信息（非支持银行返回""）
		 */
		public String bankDescription;
		/**
		 * 卡BIN信息
		 */
		public String cardBin;
		/**
		 * 1:借记卡 2:货记卡 3:预付卡 4:准贷记卡
		 */
		public String cardType;
		/**
		 * 支付方式id
		 */
		public String payId;
		/**
		 * 银行卡描述信息
		 */
		public String cardDescription;
	}

	public static class RequestParams {
		public String cardId;
	}
}
